package com.pair.micro.common.utils;

import java.util.Map;
import java.util.Random;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class GefinitionCodeUtil {
    private static final long ONE_STEP = 1000000;
    private static final Lock LOCK = new ReentrantLock();
    private static short lastCount = 1;
    private static int count = 0;
    private static final String first = "10";
    public static final String CODE_PREFIX_configId = "300";
    public static final String CODE_PREFIX_feeId = "90";
    public static final String CODE_PREFIX_detailId = "19";
    public static final String CODE_PREFIX_receiveId = "40";
    public static final String CODE_PREFIX_receiveDetailId = "50";
    public static final String CODE_PREFIX_zs = "zs";
    private static Map<String, String> prefixMap = null;
    private static String PLATFORM_CODE = "0001";
    public static String nextId(String idLength) {
        LOCK.lock();
        try {
            if (lastCount == ONE_STEP) {
                lastCount = 1;
            }
            count = lastCount++;
        } finally {
            LOCK.unlock();
            return getRandom() + String.format(idLength, count);
        }
    }
    private static String getRandom() {
        Random random = new Random();
        String result = "";
        for (int i = 0; i < 4; i++) {
            result += random.nextInt(10);
        }
        return result;
    }
    public static String getGeneratorId(String prefix){
            return prefix + DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_DEFAULT) + nextId("%04d");
    }
}
